﻿

Public Class ZipperSetter

    'Load :
    Private Sub ZipSetter_Load(sender As Object, e As System.EventArgs) Handles Me.Load
        Control.CheckForIllegalCrossThreadCalls = False
    End Sub
    'Associated Zip Designer :
    Private WithEvents _Designer As PanelZipDesigner
    Public Property Designer As PanelZipDesigner
        Get
            Return _Designer
        End Get
        Set(value As PanelZipDesigner)
            _Designer = value
        End Set
    End Property
    'Designer Events :
    Private Sub _Designer_NodeSelected(sender As Object, e As NodeSelectedEventArgs) Handles _Designer.NodeSelected
        If _SettingsEnabled = False Then
            EnableSettings()
        End If
        KHG.ValuesPrimary.Image = _Designer.ZipTreeView.ImageList.Images.Item(e.SelectedNode.ImageKey)
        KHG.ValuesPrimary.Heading = e.SelectedNode.Text
        If TypeOf e.SelectedNode Is ZipNode Then
            If CType(e.SelectedNode, ZipNode).IsRootZipNode Then
                ZSP.TargetNode = CType(e.SelectedNode, ZipNode)
                BSHG_EntrySettings.Enabled = ButtonEnabled.False
                BSHG_ZipSettings.Enabled = ButtonEnabled.True
                BSHG_ZipSettings.PerformClick()
            Else
                ZSP.TargetNode = CType(e.SelectedNode, ZipNode)
                ESP.TargetNode = CType(e.SelectedNode, ISettable)
                BSHG_EntrySettings.Enabled = ButtonEnabled.True
                BSHG_ZipSettings.Enabled = ButtonEnabled.True
                BSHG_EntrySettings.PerformClick()
            End If
        Else
            ESP.TargetNode = CType(e.SelectedNode, ISettable)
            BSHG_EntrySettings.Enabled = ButtonEnabled.True
            BSHG_ZipSettings.Enabled = ButtonEnabled.False
            BSHG_EntrySettings.PerformClick()
        End If
    End Sub
    Private Sub _Designer_RootZipNodeDeleted(sender As Object, e As System.EventArgs) Handles _Designer.RootZipNodeDeleted
        DisableSettings()
        KHG.ValuesPrimary.Image = Nothing
        KHG.ValuesPrimary.Heading = ""
    End Sub
    Private Sub _Designer_RootZipNodeCreated(sender As Object, e As RootZipNodeCreatedEventArgs) Handles _Designer.RootZipNodeCreated
        EnableSettings()
    End Sub
    'Select a Settings Panel :
    Private Sub SelectSettingsPanel(ByVal pan As String)
        Me.SuspendLayout()
        Dim pane As Control
        Dim bshg As ButtonSpecHeaderGroup
        ESP.Visible = False
        BSHG_EntrySettings.Checked = ButtonCheckState.Unchecked
        ZSP.Visible = False
        BSHG_ZipSettings.Checked = ButtonCheckState.Unchecked
        PF.Visible = False
        BSHG_Filters.Checked = ButtonCheckState.Unchecked
        Select Case pan
            Case "EntrySettings"
                pane = ESP
                bshg = BSHG_EntrySettings
                BSHG_ApplySettings.Enabled = ButtonEnabled.True
                BSHG_CancelSettings.Enabled = ButtonEnabled.True
                BSHG_ResetSettings.Enabled = ButtonEnabled.True
            Case "ZipSettings"
                pane = ZSP
                bshg = BSHG_ZipSettings
                BSHG_ApplySettings.Enabled = ButtonEnabled.True
                BSHG_CancelSettings.Enabled = ButtonEnabled.True
                BSHG_ResetSettings.Enabled = ButtonEnabled.True
            Case "Filters"
                pane = PF
                bshg = BSHG_Filters
                BSHG_ApplySettings.Enabled = ButtonEnabled.False
                BSHG_CancelSettings.Enabled = ButtonEnabled.False
                BSHG_ResetSettings.Enabled = ButtonEnabled.False
            Case Else
                pane = ESP
                bshg = BSHG_EntrySettings
                BSHG_ApplySettings.Enabled = ButtonEnabled.True
                BSHG_CancelSettings.Enabled = ButtonEnabled.True
                BSHG_ResetSettings.Enabled = ButtonEnabled.True
        End Select
        bshg.Checked = ButtonCheckState.Checked
        pane.Visible = True
        pane.BringToFront()
        Me.ResumeLayout()
    End Sub
    'Showing / Hiding ZipSetter :
    Private _SettingsVisible As Boolean = True
    Private _SettingsEnabled As Boolean = True
    Public Sub ShowSettings()
        Me.SuspendLayout()
        If _SettingsVisible = False Then
            _SettingsVisible = True
            Me.AutoSize = False
            BSHG_Toogle.Image = My.Resources.Img_Up
            BSHG_Toogle.ToolTipTitle = "Hide Settings"
        End If
        Me.ResumeLayout()
    End Sub
    Public Sub HideSettings()
        Me.SuspendLayout()
        If _SettingsVisible = True Then
            _SettingsVisible = False
            Me.AutoSize = True
            BSHG_Toogle.Image = My.Resources.Img_Down
            BSHG_Toogle.ToolTipTitle = "Show Settings"
        End If
        Me.ResumeLayout()
    End Sub
    Public Sub DisableSettings()
        If _SettingsEnabled = True Then
            _SettingsEnabled = False
            If _SettingsVisible = True Then
                BSHG_Toogle.PerformClick()
            End If
            BSHG_Toogle.Enabled = ButtonEnabled.False
        End If
    End Sub
    Public Sub EnableSettings()
        If _SettingsEnabled = False Then
            _SettingsEnabled = True
            BSHG_Toogle.Enabled = ButtonEnabled.True
        End If
    End Sub
    'Selection Panel :
    Private Sub BSHG_EntrySettings_Click(sender As System.Object, e As System.EventArgs) Handles BSHG_EntrySettings.Click
        SelectSettingsPanel("EntrySettings")
    End Sub
    Private Sub BSHG_ZipSettings_Click(sender As System.Object, e As System.EventArgs) Handles BSHG_ZipSettings.Click
        SelectSettingsPanel("ZipSettings")
    End Sub
    Private Sub BSHG_Filters_Click(sender As System.Object, e As System.EventArgs) Handles BSHG_Filters.Click
        SelectSettingsPanel("Filters")
    End Sub
    'Toogle Visible / Hidden State :
    Private Sub BSHG_Toogle_Click(sender As System.Object, e As System.EventArgs) Handles BSHG_Toogle.Click
        If _SettingsVisible = True Then
            HideSettings()
        Else
            ShowSettings()
        End If
    End Sub
    'Actions :
    Private Sub BSHG_ResetSettings_Click(sender As System.Object, e As System.EventArgs) Handles BSHG_ResetSettings.Click
        If ESP.Visible = True Then
            ESP.Reset()
        ElseIf ZSP.Visible = True Then
            ZSP.Reset()
        End If
    End Sub
    Private Sub BSHG_CancelSettings_Click(sender As System.Object, e As System.EventArgs) Handles BSHG_CancelSettings.Click
        If ESP.Visible = True Then
            ESP.Cancel()
        ElseIf ZSP.Visible = True Then
            ZSP.Cancel()
        End If
    End Sub
    Private Sub BSHG_ApplySettings_Click(sender As System.Object, e As System.EventArgs) Handles BSHG_ApplySettings.Click
        If ESP.Visible = True Then
            ESP.Apply()
        ElseIf ZSP.Visible = True Then
            ZSP.Apply()
        End If
    End Sub

End Class
